/**
 * @Title: FileTransferServiceImpl.java
 * @Copyright (C) 2017 龙图软件
 * @Description:
 * @Revision History:
 * @Revision 1.0 2017-11-21  yuanchunci
 */
 

package com.ycc.fileTransfer.service.impl;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ycc.fileTransfer.entity.FileTable;
import com.ycc.fileTransfer.entity.FormFile;
import com.ycc.fileTransfer.mapper.FileTransferMapper;
import com.ycc.fileTransfer.service.FileTransferService;

/**
 * @ClassName: FileTransferServiceImpl
 * @Description: Description of this class
 * @author <a href="mailto:XXX@qq.com">yuanchunci</a>于 2017-11-21 上午9:35:44
 */
@Service("FileTransferService")
public class FileTransferServiceImpl implements FileTransferService{
 @Resource
 FileTransferMapper fileTransferMapper;

/**.
 * <p>Title: insertOne</p>
 * <p>Description: </p>
 * @param p
 * @throws Exception
 * @see com.ycc.fileTransfer.service.FileTransferService#insertOne(java.util.Map)
 */
@Override
public void insertOne(Map p) throws Exception {
	
//	fileTransferMapper.getOne(p);
//	p.put("content", p.get("data"));
	p.put("thumbnail", p.get("ThumbnailData"));
	fileTransferMapper.insertOne(p);
//	fileTransferMapper.updateOne(p);
}

/**.
 * <p>Title: get</p>
 * <p>Description: </p>
 * @param p
 * @return
 * @throws Exception
 * @see com.ycc.fileTransfer.service.FileTransferService#get(java.util.Map)
 */
@Override
public List get(Map p) throws Exception {
	// TODO Auto-generated method stub
	return fileTransferMapper.get(p);
}

/**.
 * <p>Title: delete</p>
 * <p>Description: </p>
 * @param s
 * @throws Exception
 * @see com.ycc.fileTransfer.service.FileTransferService#delete(java.lang.String)
 */
@Override
public int delete(String s) throws Exception {
	Map p=new HashMap();
	p.put("id", s);
	List<FormFile> ls=fileTransferMapper.get(p);
	if(ls.size()>0){
		String path=ls.get(0).getFilepath();
		String thumpath=ls.get(0).getThumbnailname();
		File f=new File(path);
		if(f.exists()){
			f.delete();
		}
		if(ls.get(0).getThumbnailname() != null){
			File thumf=new File(thumpath);
			if(thumf.exists()){
				thumf.delete();
			}
		}
		
	}
	return fileTransferMapper.delete(s);
}
}
